package com.sidianzhong.sdz.service.impl;
import com.github.pagehelper.PageHelper;
import com.sidianzhong.sdz.mapper.*;
import com.sidianzhong.sdz.model.*;
import com.sidianzhong.sdz.service.*;
import com.sidianzhong.sdz.utils.PageInfo;
import com.sidianzhong.sdz.utils.Tools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;

/**
* Created by hxgqh on 2016/1/7.
*/
@Service
@Transactional
public class AppZequipmentgrouprecordServiceImpl implements AppZequipmentgrouprecordService{
    protected static final Logger LOG = LoggerFactory.getLogger(AppZequipmentgrouprecordServiceImpl.class);

    // 将所有的modelMapper注入
    @Autowired
    private AppZequipmentgrouprecordMapper appZequipmentgrouprecordMapper;


    @Override
    public AppZequipmentgrouprecord create(AppZequipmentgrouprecord item) {

         appZequipmentgrouprecordMapper.insert(item);
         return item;
    }

    @Override
    public int delete(Integer id) {
        return appZequipmentgrouprecordMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(AppZequipmentgrouprecord item) {

        return appZequipmentgrouprecordMapper.updateByPrimaryKeySelective(item);
    }

    @Override
    public AppZequipmentgrouprecord get(Integer id) {
        return appZequipmentgrouprecordMapper.selectByPrimaryKey(id);
    }
    @Override
     public PageInfo<AppZequipmentgrouprecord> getListWithPaging(Integer pageNum, Integer pageSize,
                                                  String sortItem, String sortOrder,AppZequipmentgrouprecord item){

        AppZequipmentgrouprecordExample  example = new AppZequipmentgrouprecordExample();
        AppZequipmentgrouprecordExample.Criteria criteria = example.createCriteria();
        if(item.getEquipmentkey() != null ){
            criteria.andEquipmentkeyEqualTo(item.getEquipmentkey());
        }
        if(item.getOwnkey() != null ){
            criteria.andOwnkeyEqualTo(item.getOwnkey());
        }
        if(item.getValue() != null ){
            criteria.andValueEqualTo(item.getValue());
        }
        if(item.getValuetype() != null ){
            criteria.andValuetypeEqualTo(item.getValuetype());
        }
        if(item.getValuesize() != null ){
            criteria.andValuesizeEqualTo(item.getValuesize());
        }

        example.setOrderByClause(Tools.humpToLine(sortItem)+" "+sortOrder);
        PageHelper.startPage(pageNum, pageSize);
        List< AppZequipmentgrouprecord> list = this.appZequipmentgrouprecordMapper.selectByExample(example);
        PageInfo result = new PageInfo(list);

        return result;

     }

    @Override
    public AppZequipmentgrouprecord getOne(String equipmentkey, String ownkey) {
        return this.appZequipmentgrouprecordMapper.getOne(equipmentkey, ownkey);
    }

}
